Telegram Group & Telegram Channel
Python dasturlash maktabi
Kortej.png
Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz



tg-me.com/pythonuz/416
Create:
Last Update:

Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz

BY Python dasturlash maktabi


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pythonuz/416

View MORE
Open in Telegram


Python dasturlash maktabi Telegram | DID YOU KNOW?

Date: |

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Python dasturlash maktabi from ar


Telegram Python dasturlash maktabi
FROM USA